package com.zsgeek.wisdchain.qutu.view.find;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zsgeek.wisdchain.qutu.BaseActivity;
import com.zsgeek.wisdchain.qutu.R;
import com.zsgeek.wisdchain.qutu.base.customControl.EmptyRecyclerView;
import com.zsgeek.wisdchain.qutu.base.customControl.RecyclerItemDecoration;
import com.zsgeek.wisdchain.qutu.base.model.GetAdverListModel;
import com.zsgeek.wisdchain.qutu.tools.ImageUtils;
import com.zsgeek.wisdchain.qutu.tools.TextUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 搜索结果
 */
public class SearchResultActivity extends BaseActivity {
    @BindView(R.id.list_date_emptyView)
    View list_date_emptyView;
    @BindView(R.id.recyclerView)
    EmptyRecyclerView emptyRecyclerView;

    private List<GetAdverListModel.DataBean> dataListBeans = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.activity_search_resoult;
    }

    @Override
    protected void initView() {
        setTitle("查询结果");

        dataListBeans = (List<GetAdverListModel.DataBean>) getIntent().getSerializableExtra("dataList");
        emptyRecyclerView.addItemDecoration(new RecyclerItemDecoration(3, 2));
        emptyRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        emptyRecyclerView.setEmptyView(list_date_emptyView);
        mAdapter.setNewData(dataListBeans);
        emptyRecyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                startActivityForResult(new Intent(SearchResultActivity.this, FindDetailsActivity.class)
                        .putExtra("data", dataListBeans.get(position)), 0x100);
            }
        });
    }

    @Override
    protected void initDate(Bundle savedInstanceState) {

    }

    private BaseQuickAdapter<GetAdverListModel.DataBean, BaseViewHolder> mAdapter =
            new BaseQuickAdapter<GetAdverListModel.DataBean, BaseViewHolder>(R.layout.fragment_recommend_item, dataListBeans) {
                @Override
                protected void convert(BaseViewHolder baseViewHolder, final GetAdverListModel.DataBean dataBean) {
                    baseViewHolder.setText(R.id.content_tv, dataBean.getLabel());
                    baseViewHolder.setText(R.id.nick_name_tv, dataBean.getNickName());
                    baseViewHolder.setText(R.id.love_tv, dataBean.getAgreeNum() + "");
                    ImageUtils.loadImage(SearchResultActivity.this,
                            dataBean.getIsDianzan()==2 ? R.mipmap.love_hollow_red_bg : R.mipmap.love_hollow_white_bg,
                            baseViewHolder.getView(R.id.love_iv));
                    ImageUtils.loadImage(SearchResultActivity.this, dataBean.getHeadImg(), baseViewHolder.getView(R.id.title_icon_iv));

                    List<GetAdverListModel.DataBean.ImgesBean> imges = dataBean.getImges();
                    if (!TextUtils.isEmpty(imges)) {
                        ImageUtils.loadImage(SearchResultActivity.this, imges.get(0).getImgUrl(), baseViewHolder.getView(R.id.avatar_iv));
                    }
                }
            };
}
